package com.ruoyi.orderview.service.impl;
import com.ruoyi.orderview.service.StromaChartsService;
import com.ruoyi.orderview.utils.DateDispose;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.ruoyi.orderview.mapper.StromaChartsMapper;
import com.ruoyi.orderview.domain.ProductionParam;


import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;
/**
 * Author 许家森
 * Date 2022/2/22
 * Email 3448324670@qq.com
 */
@Service
public class StromaChartsServiceImpl implements StromaChartsService {
    @Autowired
    private StromaChartsMapper stromaChartsMapper;

    @Autowired
    private DateDispose dateDispose;
    @Override
    public List<List<Map<Object,Object>>> selectStromaAmount(ProductionParam productionParam) {
        ArrayList stroma=new ArrayList();
        SimpleDateFormat f = new SimpleDateFormat("yyyy-MM-dd");
        String origintime=f.format(productionParam.getOrigintime());
        String endtime=f.format(productionParam.getEndtime());

        ProductionParam productionParam1=dateDispose.DateDisposes(productionParam);

        List<Map<Object,Object>> stromaupdate=stromaChartsMapper.selectStromaUpdate(origintime,f.format(productionParam1.getEndtime()));
        if(stromaChartsMapper.selectStromaUpdateOrigin(origintime,endtime)!=null
                &&((
                stromaupdate.size()>0
                &&
                !stromaupdate.get(0).get("update_time").toString().equals(origintime))
                ||
                stromaupdate.size()==0))

        {
            stromaupdate.add(0, stromaChartsMapper.selectStromaUpdateOrigin(origintime,endtime));
        }
        stroma.add(stromaChartsMapper.selectStromaPurchase(origintime,endtime));
        stroma.add(stromaChartsMapper.selectStromaConsume(origintime,endtime));
        stroma.add(stromaChartsMapper.selectStromaConsumeTemporary(origintime,endtime));
        stroma.add(stromaChartsMapper.selectStromaReturn(origintime,endtime));
        stroma.add(stromaupdate);
        stroma.add(stromaChartsMapper.selectStromaPurcahseTotal(origintime,endtime));
        return  stroma;
    }
}
